import { defineStore } from "pinia";
import { getStructureTree } from "@/service/api/report.js";
export const useReportOrderDetail = defineStore("reportOrderDetail", {
    state: () => {
        return {
            //1 新增 2 审核 3 详情 4 处理 5 派发 6 验收
            stateOperation: 0,
            treeData: [],
            treeSelectNode: {},
            repairDetail: [],
            expanded: []
        };
    },
    actions: {
        getDeviceTree({ id, strategyId, structureType }, callBack) {
            getStructureTree({
                id,
                strategyId,
                structureType
            }).then((res) => {
                if (res.code === 200) {
                    recursionData(res.data);
                    function recursionData(arr) {
                        for (let i = 0; i < arr.length; i++) {
                            if (arr[i].depth !== "0") {
                                arr[i].hot = [];
                                arr[i].imgList = [];
                                arr[i].reamrk = "";
                            } else {
                                arr[i].hot = 0;
                            }
                            if (!arr[i].childList.length) continue;
                            recursionData(arr[i].childList);
                        }
                    }
                    this.treeData = res.data;
                    this.expanded = [res.data[0]?.id || 0];
                    if (callBack) callBack();
                }
            });
        }
    }
    // persist: {
    //     enabled: true,
    //     strategies: [
    //         {
    //             paths: ["stateOperation"]
    //         }
    //     ]
    // }
});
